package main;

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

import org.softmed.rest.admin.ModuleManager;
import org.softmed.rest.admin.config.ConfigurationActionPanel;
import org.softmed.swing.IconManager;

public class DevToolBar extends JMenuBar implements ActionListener {

	private static final long serialVersionUID = -9049562565758490119L;

	private final int ITEM_PLAIN = 0;

	private final int ITEM_CHECK = 1;

	private final int ITEM_RADIO = 2;

	int width = 20;
	int height = 20;

	JToolBar bar;

	private RESTEditor editor;

	public DevToolBar(JToolBar bar, RESTEditor editor) {
		this.bar = bar;
		this.editor = editor;

		// bar.add();

	}

	protected JButton createButton(String name) {
		JButton c1 = new JButton();
		c1.setText(name);
		c1.setMargin(new Insets(0, 0, 0, 0));
		c1.addActionListener(this);
		return c1;
	}

	protected JToggleButton createToggleButton(String name) {
		JToggleButton c1 = new JToggleButton();
		c1.setText(name);
		c1.setMargin(new Insets(0, 0, 0, 0));
		c1.addActionListener(this);
		return c1;
	}

	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();

		// if (source == create) {
		// editor.addNewModule();
		// } else if (source == save) {
		// editor.saveAllConfiguration();
		// } else if (source == load) {
		// editor.loadConfiguration();
		// } else if (source == saveConfigurationFileOnly) {
		// editor.saveConfigurationOnly();
		// }

	}

	public JMenuItem CreateMenuItem(String sText) {
		return CreateMenuItem(null, ITEM_PLAIN, sText, null, 0, null);
	}

	public JMenuItem CreateMenuCheckItem(String sText) {
		return CreateMenuItem(null, ITEM_CHECK, sText, null, 0, null);
	}

	public JMenuItem CreateMenuItem(JMenu menu, int iType, String sText,
			ImageIcon image, int acceleratorKey, String sToolTip) {
		// Create the item
		JMenuItem menuItem;

		switch (iType) {
		case ITEM_RADIO:
			menuItem = new JRadioButtonMenuItem();
			break;

		case ITEM_CHECK:
			menuItem = new JCheckBoxMenuItem();
			break;

		default:
			menuItem = new JMenuItem();
			break;
		}

		// Add the item test
		menuItem.setText(sText);

		// Add the optional icon
		if (image != null)
			menuItem.setIcon(image);

		// Add the accelerator key
		if (acceleratorKey > 0)
			menuItem.setMnemonic(acceleratorKey);

		// Add the optional tool tip text
		if (sToolTip != null)
			menuItem.setToolTipText(sToolTip);

		// Add an action handler to this menu item
		menuItem.addActionListener(this);

		if (menu != null)
			menu.add(menuItem);

		return menuItem;
	}

	protected void addButton(JButton button) {
		resizeButton(button, width, height);
		button.addActionListener(this);
		add(button);
	}

	protected void resizeButton(JButton button, int width, int height) {
		button.setPreferredSize(new Dimension(width, height));
		button.setMaximumSize(new Dimension(width, height));
		button.setMinimumSize(new Dimension(width, height));
	}

}
